package com.example.studyPlatform.mapper;

import com.example.studyPlatform.bean.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    @Select("select * from users where username = #{username} and password = #{password}")
    User login(String username, String password);

    @Insert("insert into users (username, password,email) value (#{username}, #{password},#{email}) ")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    int register(User user);

    @Select("select (select count(id) from users where username = #{username}) > 0 ")
    boolean hasUserName(String username);

    @Select("select * from users where id=#{id} ")
    User getUserById(int id);
}
